<?php

namespace App\Console\Commands\Tasks;
use Illuminate\Console\Command;
use App\Http\Controllers\Common\TaskController;

class ConnectOpenBoxCommand extends Command
{
    //命令名
    protected $signature = 'task:connect_box';

    //命令描述：每分钟检查是否有未开启的礼物盒子
    protected $description = 'connectBox';

    public function __construct()
    {
        parent::__construct();
    }

    //业务处理
    public function handle()
    {
        //1次/min
        $list = app('model_connection_send_record')->where([
            'status' => 1
        ])->where([
            ['created_at', '<=', date('Y-m-d H:i:s',time()-60)]
        ])->limit(30)->orderBy('id','desc')->get();
        $list = empty($list)?[]:$list->toArray();
        foreach ($list as $k=>$v){
            $giftInfo = app('model_gift')->where('id',$v['gift_id'])->first(['name','id','prize_pool_group_id']);
            if(empty($giftInfo)){
                continue;
            }
            $giftInfo = $giftInfo->toArray();
            $giftInfo['give_number'] = $v['number'];
            $data = [
                'giftInfo' => $giftInfo,
                'room_id' => 0,
                'connectSendRecord' => $v,
            ];
            $res = app('repo_new_connect')->openConnectGiftBoxOperate($data,true);
            var_dump($res);
        }
    }

}